package org.example.service;

import org.example.dao.BookDaoImp;
import org.example.model.book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class BookServiceImp implements BookService {
    @Autowired
    BookDaoImp bookDaoImp;
    @Override
    public boolean addBook(book book) {
        if (bookDaoImp.isExistById(book.getId())) return false;
        bookDaoImp.insert(book);
        return true;
    }
    @Override
    public boolean updateBook(book book) {
        if (!bookDaoImp.isExistById(book.getId())) return false;
        bookDaoImp.update(book);
        return true;
    }
    @Override
    public boolean deleteBook(String id) {
        if (!bookDaoImp.isExistById(id)) return false;
        bookDaoImp.delete(id);
        return true;
    }
    @Override
    public book[] queryAll() {return bookDaoImp.queryAll().toArray(new book[0]);}
    @Override
    public book queryBookById(String id) {
        return bookDaoImp.queryById(id);
    }
    @Override
    public book[] queryBookByName(String name) {
        return bookDaoImp.queryByName(name).toArray(new book[0]);
    }
}
